package com.yuexun.dhdoctor.module.meetingNew.presenter.impl;

import com.yuexun.dhdoctor.base.BaseEntity;
import com.yuexun.dhdoctor.module.meetingNew.bean.MeetingNewRoleBean;
import com.yuexun.dhdoctor.module.meetingNew.bean.MeetingNewRoomBean;
import com.yuexun.dhdoctor.module.meetingNew.bean.MeetingNewRoomBeanNew;
import com.yuexun.dhdoctor.module.meetingNew.model.IMeetingNewModel;
import com.yuexun.dhdoctor.module.meetingNew.presenter.IMeetingNewAddPresenter;
import com.yuexun.dhdoctor.module.meetingNew.ui.view.IMeetingNewAddView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by wangt on 2017/12/19.
 */

public class MeetingNewAddPresenter implements IMeetingNewAddPresenter {
    private IMeetingNewModel model;
    private IMeetingNewAddView view;

    public MeetingNewAddPresenter(IMeetingNewModel model, IMeetingNewAddView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void getRoomList(Map<String, String> praise) {
        model.getRoomList(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<MeetingNewRoomBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(BaseEntity<MeetingNewRoomBean> bean) {
                        view.showRoomList(bean);
                    }
                });
    }

    @Override
    public void getRoleList(Map<String, String> praise) {
        model.getRoleList(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<MeetingNewRoleBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(BaseEntity<MeetingNewRoleBean> bean) {
                        view.showRoleList(bean);
                    }
                });
    }

    @Override
    public void createMeeting(String[] participantIds, String[] readyIds,
                              String[] deptIdList, String[] deptSignCountList,
                              String[] groupIdList, String[] groupSignCountList,
                              Map<String, String> praise) {
        model.createMeeting(participantIds, readyIds, deptIdList, deptSignCountList, groupIdList, groupSignCountList, praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<String>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(BaseEntity<String> bean) {
                        view.createMeeting(bean);
                    }
                });
    }

    @Override
    public void getRoomList2(Map<String, String> praise) {
        model.getRoomList2(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<MeetingNewRoomBeanNew>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(BaseEntity<MeetingNewRoomBeanNew> bean) {
                        view.showRoomList2(bean);
                    }
                });
    }

}
